/*
 * Copyright (C) 2004, Velocityme Partnership
 * PostCommentActionForm.java
 *
 * Created on 05 September 2004, 08:33
 */

package com.velocityme.www.actionforms;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
import org.apache.struts.upload.MultipartRequestHandler;

/**
 *
 * @author  Robert
 */
public class PostCommentActionForm extends ActionForm {
    
    private String m_comment;
    
    private FormFile m_file;
    
    /** Creates a new instance of NodeValueActionForm */
    public PostCommentActionForm() {
    }
    
    public String getComment() {
        return m_comment;
    }
    
    public void setComment(String comment) {
        m_comment = comment;
    }
    
    public FormFile getFile() {
        return m_file;
    }
    
    public void setFile(FormFile file) {
        m_file = file;
    }
    
    /**
     * Check to make sure the client hasn't exceeded the maximum allowed upload size inside of this
     * validate method.
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = null;
        //has the maximum length been exceeded?
        Boolean maxLengthExceeded = (Boolean)request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
        if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
            errors = new ActionErrors();
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.file.maxLengthExceeded"));
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.file.maxLengthExplanation"));
        }
        return errors;
    }
}
